<%@page import="com.google.appengine.api.users.UserService"%>
<%@page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@page import="com.google.appengine.api.users.User"%>
<%@page import="it.cpyx.appengine.server.data.utils.TextDataUtils"%>
<%@page import="java.util.List"%>
<%@page import="it.cpyx.appengine.server.data.TextData"%>
<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="it.cpyx.appengine.server.data.PMF"%>
<%@page import="it.cpyx.appengine.server.data.LabelData"%>
<%@page import="java.util.Iterator"%>
<%@page import="it.cpyx.appengine.server.data.utils.LabelDataUtils"%>
	<a href="/">home</a>
		<hr>
<%
	UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
%>
		<p>Hello, <%=user.getNickname()%>! (You can <a href="<%=userService.createLogoutURL(request.getRequestURI())%>">sign out</a>.)</p>
<%
	} else {
%>
		<p>Hello! <a href="<%=userService.createLoginURL(request.getRequestURI())%>">Sign in</a>.</p>
<%
	}
%><hr>
	
		index<%=request.getPathInfo()%>
		<hr>
	    <form action="/s" method="post">
	    	<div>text:</div>
	    	<div><textarea  name="content" rows="20" cols="100"></textarea></div>
	    	<div>//optional</div>
	    	<div>Title:</div>
	    	<div><input name="title"/></div>
	    	<div>Labels:</div>
	    	<div><input name="labels"/></div>
	    	<div>pass:</div>
	    	<div><input name="password"/></div>
	    	<div>Custom alias:</div>
	    	<div><input name="manualId"/></div>
	    	<div><input type="submit" value="CpyX.IT" /></div>

	    </form>
	    <hr>Size:<%=TextDataUtils.getSizeOfTextData()%>
	    
	    <hr><hr>Texts urlextensions<br>
<%
	PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + TextData.class.getName() ;
    List<TextData> textDatas = (List<TextData>) pm.newQuery(query).execute();
    if (textDatas.isEmpty()) {
%>
<p>nothing.</p>
<%
	} else {
        for (TextData t : textDatas) {
%>
<blockquote><%=t.getUrlExtension()%></blockquote>
<blockquote><b>lbl:</b>
<%
	
	Iterator it = t.getLabelDataList().iterator(); 
	while (it.hasNext()) {  
		Object element = it.next();
		LabelData l=LabelDataUtils.getById(Long.parseLong(element.toString()));
		%><a href="/tags/<%=l.getUrlExtension() %>"><%=l.getUrlExtension() %></a>   ,
	<%
	}%>
	</blockquote>
<%
	}
    }
    pm.close();
%>


////////////////////////////////////////////////////////////////
	  <hr><hr>lbls:
Texts urlextensions<br>
<%
	PersistenceManager pm2 = PMF.get().getPersistenceManager();
    String query2 = "select from " + LabelData.class.getName() ;
    List<LabelData> labelDatas = (List<LabelData>) pm2.newQuery(query2).execute();
    if (labelDatas.isEmpty()) {
%>
<p>nothing.</p>
<%
    } else {
        for (LabelData l : labelDatas) {
%>
<blockquote><%= l.getUrlExtension() %></blockquote>
<blockquote><b>texts:</b>
<% 
	Iterator it = l.getTextDataList().iterator(); 
	while (it.hasNext()) {  
		Object element = it.next();
		TextData t2=TextDataUtils.getById(Long.parseLong(element.toString()));
		%><a href="/<%=t2.getUrlExtension()%>"><%=t2.getUrlExtension() %></a> ,
	<%
	}%>
		</blockquote>
<br>
<%
        }
    }
    pm2.close();
%>  
	    
    </body>
</html>